package com.hujf.flink.DataSet;

import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.aggregation.Aggregations;
import org.apache.flink.api.java.operators.AggregateOperator;
import org.apache.flink.api.java.tuple.Tuple3;

/**
 * @Author hujf
 * @Date 2022/5/19 10:35
 * @Description TODO
 */
public class AggtrDataSet {
    public static void main(String[] args) throws Exception {
        ExecutionEnvironment environment = ExecutionEnvironment.getExecutionEnvironment();

        DataSet<Tuple3<Integer, String, Double>> tuple2DataSource = environment.fromElements(new Tuple3<>(2,"2",1.0),
                new Tuple3<>(3, "2",3.0),
                new Tuple3<>(4, "3",3.0),
                new Tuple3<>(3,"3",2.0));
        AggregateOperator<Tuple3<Integer, String, Double>> and = tuple2DataSource.groupBy(1)
                .aggregate(Aggregations.SUM, 0)
                .and(Aggregations.MIN, 2);

        AggregateOperator<Tuple3<Integer, String, Double>> aggregate = tuple2DataSource.groupBy(1).aggregate(Aggregations.SUM, 0)
                .aggregate(Aggregations.MIN, 2);

        and.print();
        System.out.println("---------------------------");
        aggregate.print();


    }
}
